%小信噪比下的遍历容量

clear
clc
NUM_timesamples = 1000;
tilde_h = (randn(NUM_timesamples)+ j*randn(NUM_timesamples))/sqrt(2);
Pathloss = 1;
h = sqrt(Pathloss)*tilde_h;
SNR_dB = -10:1:10;

% 小信噪比
for I_SNR = 1: length(SNR_dB)
    rho = 10^(SNR_dB(I_SNR)/10);
    
    for t = 1:NUM_timesamples
    h_temp(t) = h(t)*h(t)';
    end
    h_average= sum(h_temp)/NUM_timesamples;

    Capacity_low(I_SNR)=rho*h_average*log2(exp(1));
end

subplot(2, 1, 1); % 第一个子图
hold on
plot(SNR_dB,Capacity_low, 'co-')

legend('Capacity(low)', 'Location', 'NorthWest'),

title('小信噪比下遍历容量与信噪比的关系(路径损耗=1)');
xlabel('\rho (in dB)')
ylabel('Ergodic Capacity (bps/Hz)')
grid

Pathloss = 5;
h = sqrt(Pathloss)*tilde_h;

% 小信噪比
for I_SNR = 1: length(SNR_dB)
    rho = 10^(SNR_dB(I_SNR)/10);
    
    for t = 1:NUM_timesamples
    h_temp(t) = h(t)*h(t)';
    end
    h_average= sum(h_temp)/NUM_timesamples;

    Capacity_low(I_SNR)=rho*h_average*log2(exp(1));
end

subplot(2, 1, 2); % 第二个子图
hold on
plot(SNR_dB,Capacity_low, 'co-')
legend('Capacity(low)', 'Location', 'NorthWest'),

title('小信噪比下遍历容量与信噪比的关系(路径损耗=5)');
xlabel('\rho (in dB)')
ylabel('Ergodic Capacity (bps/Hz)')
grid